﻿$(function() {
    $('.comic-box .add').on('click', function() {
        var index = $('.comic-box .comic-item').length;
        $('.comic-box .box-body').append([
            '<div class="form-group comic-item">',
            '<div class="row">',
            '<div class="col-xs-2">',
            '<input type="text" class="form-control" name="ComicItems[' + index + '].Num" placeholder="第几集" value="" />',
            '</div>',
            '<div class="col-xs-6">',
            '<input type="text" class="form-control" name="ComicItems[' + index + '].Url" placeholder="地址" value="" />',
            '</div>',
            '<div class="col-xs-2">',
            '<button type="button" class="btn btn-danger delete"><i class="fa fa-times-circle"></i></button>',
            '</div>',
            '</div>',
            '</div>'
        ].join(''));
    });
    $('.comic-box').on('click', '.delete', function() {
        var $el = $(this);
        var id = $el.data('id');
        if (id && !confirm('确定删除吗？')) {
            return false;
        }

        $.post('../DeleteComicItem', { id: id }, function() {
            $el.closest('.form-group').remove();
        });
    });

    $('#fileupload').fileupload({
            url: '../../Image/Upload',
            dataType: 'json',
            done: function(e, data) {
                $('#submit').prop('disable', false);
                $('#imageId').val(data.result);
                if (typeof uploadCallback === "function") uploadCallback();
            },
            start: function() {
                $('#submit').prop('disable', true);
            },
            progressall: function(e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                $('#progress .progress-bar').css(
                    'width',
                    progress + '%'
                );
            }
        }).prop('disabled', !$.support.fileInput)
        .parent().addClass($.support.fileInput ? undefined : 'disabled');
});